<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Home Page</title>
</head>
<body>
    <h1 th:text="${message}"></h1>
    <a href="/logout">Logout</a>
    <button onclick="adminPage();">管理员</button>

    <script>
		console.log("管理员页面");

        function adminPage() {
			console.log("跳转管理员页面");
            const token = localStorage.getItem('token');
            // 手动触发携带 Authorization 头的页面跳转
            const xhr = new XMLHttpRequest();
            xhr.open('GET', '/admin', true);
            xhr.setRequestHeader('Authorization', `Bearer ${token}`);
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        // 替换当前页面内容
                        document.documentElement.innerHTML = xhr.responseText;
                    } else {
                        document.getElementById('errorMessage').textContent = '跳转页面请求失败，请稍后重试';
                    }
                }
            };
            xhr.send();
        }
    </script>
</body>
</html>
